# Maintainer: Jakob Meier <comcloudway@ccw.icu>
# Contributor: Jakob Meier <comcloudway@ccw.icu>
# Contributor: Grigory Kirillov <txgk@bk.ru>
pkgname=maxima
pkgver=5.47.0
pkgrel=7
pkgdesc="Sophisticated computer algebra system"
url="http://maxima.sourceforge.net"
# riscv64: TODO after Alpine 3.20
arch="all !riscv64"
license="GPL-2.0-or-later"
_ecl_version="23.9.9"
depends="texinfo shared-mime-info"
makedepends="
	autoconf
	automake
	ecl-dev~=$_ecl_version
	gc-dev
	gmp-dev
	libffi-dev
	perl
	python3
	"
checkdepends="gnuplot"
subpackages="
	$pkgname-doc
	$pkgname-doc-extra
	$pkgname-bash-completion
	$pkgname-emacs
	"
source="
	maxima-$pkgver.tar.gz::https://sourceforge.net/projects/maxima/files/Maxima-source/$pkgver-source/maxima-$pkgver.tar.gz/download
	handle-multiple-ldflags.patch
	"
options="!check" # take hours

prepare() {
	default_prepare
	autoreconf -fi
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--libexecdir=/usr/lib \
		--localstatedir=/var \
		--enable-ecl \
		--with-default-lisp=ecl
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	# remove unused files
	find "$pkgdir" -type d -iname tests -exec rm -r {} \+

	install -Dm664 src/binary-ecl/maxima.fas -t "$pkgdir"/usr/lib/ecl-$_ecl_version/
}

extra() {
	pkgdesc="$pkgdesc (extra html documentation + demos)"

	amove usr/share/$pkgname/$pkgver/doc
	amove usr/share/$pkgname/$pkgver/demo
}

emacs() {
	depends="$pkgname=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel emacs"
	pkgdesc="Emacs plugins for $pkgname"

	amove usr/share/emacs
}

sha512sums="
953b98336eb086069edaa917981372450ce165dedd7a7b39b181d3f2d8b089551eea943e0084148eaa3ded395dcba9135509d3d11d9132ab7a3ad8bb800d3a11  maxima-5.47.0.tar.gz
58b574a91f14aa1568b43ce96ac847babed75e91b68be25f40d7da1f09d1e4c8a37f549d33d7566c54e546f4825e8f8f9038777460beea0d3f9282e1ead27eb0  handle-multiple-ldflags.patch
"
